//
// Created by Eric on 2023/1/22.
// Counter统一处理模拟过程中所有的数值计算
//

#ifndef UUU_COUNTER_H
#define UUU_COUNTER_H
#include <random>
#include "uuu_utility.h"
#include <unordered_set>

using namespace std;

default_random_engine e(static_cast<unsigned int>(time(nullptr)));

//返回[left,right]内的一个整数 依赖库random
int GetRanNum(int left, int right) {
    uniform_int_distribution<int> u(left, right);
    return u(e);
}

/* DEMO:
int main(){
   int ran = GetRanNum(0,3);
   cout << ran;
   return 0;
}*/

//返回[left,right]内的一个浮点数 依赖库random
double GetRanNum(double left, double right) {
    uniform_real_distribution<double> u(left, right);
    return u(e);
}

/* DEMO:
int main(){
   int ran = GetRanNum(0.0,3.2);
   cout<<ran;
   return 0;
}*/

double GetRanNum(double right){
    return uniform_real_distribution<double>(0, right)(e);
}

// 用来处理模拟中所有的公式和数值计算

class Counter {
public:
    static unordered_set<Coord, Coord::HashFunction> coord_existed;
public:

    // 计算科技水平变化量
    static double delta_technology_level(double technology_level, double intelligence){
        return technology_level + technology_level * 0.1 + intelligence;
    }

    // 始祖文明的基础科技水平数值
    static int first_technology_level(){
        return GetRanNum(50, 100);
    }
    // 始祖文明的基础军事水平数值
    static int first_military_level(){
        return GetRanNum(50, 100);
    }

    // 始祖文明的基础好战程度
    static double first_warlike(){
        return GetRanNum(0.0, 1.0);
    }

    // 始祖文明的基础智能水平数值
    static int first_intelligence(){
        return GetRanNum(50, 100);
    }

    // 始祖文明的基础能量水平数值
    static int first_energy(){
        return GetRanNum(50, 100);
    }

    // 初始天体的基础资源水平
    static int first_resource(){
        return GetRanNum(50000, 100000);
    }



    // 初始天体的的坐标位置
    static Coord first_coord(double universe_size){
        Coord new_coord;
        do {
            new_coord.x = GetRanNum(universe_size);
            new_coord.y = GetRanNum(universe_size);
            new_coord.z = GetRanNum(universe_size);
        }while(coord_existed.count(new_coord));

        return new_coord;
    }



    // 传入概率，进行测试，返回布尔值
    static bool ChanceTest(double chance){
        return bernoulli_distribution(chance)(e);
    }

    // 获取可观测范围
    static double ob_range(double cz_technology_level, double universe_size){
//        return (cz_technology_level / 10000.0) * universe_size * 1.41421;
        return 1000;
    }
};
unordered_set<Coord, Coord::HashFunction> Counter::coord_existed = std::unordered_set<Coord, Coord::HashFunction>();

#endif //UUU_COUNTER_H
